package mo.leetcode_hot;

import mo.common.ListNode;

import java.util.Arrays;

public class L206 {

    public ListNode reverseList(ListNode head) {
        if (head == null || head.next == null) {
            return head;
        }
        ListNode pre = null;
        ListNode cur = head;
        while (cur != null) {
            ListNode next = cur.next;
            cur.next = pre;
            pre = cur;
            cur = next;

        }
        return pre;
    }

    public static void main(String[] args) {
        L206 test = new L206();
        System.out.println(test.reverseList(ListNode.convertList2ListNode(Arrays.asList(1, 2, 3, 4, 5))));
    }
}
